﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBatisNet.DataMapper;
using DevExpress.XtraTreeList;
using uIBTv.Model;
using System.Data;
using uIBTv.Domain;

using uIBTv.Extension;

namespace uIBTv.Controller
{
    
    public class BoPhanController
    {
        SqlMapper sqlMapper =Service.Mapper.Instance();
        BoPhanCollection BoPhanCollection;
        Service.BoPhanService BoPhanService;
        ViTriCollection ViTricollection;
        Service.ViTriService ViTriService;

        public DataSet GetBoPhan()
        {
          
            BoPhanCollection = (Model.BoPhanCollection)sqlMapper.QueryForList("GetBoPhan", null);
            BoPhanService = new Service.BoPhanService(BoPhanCollection);
            DataSet dsBophan = new DataSet();            
            dsBophan = BoPhanService.DataSetBoPhan;

            
            

            return dsBophan;
        }

        public DataTable GetBophanVitri()
        {
            //Domain.BoPhan ps = (Domain.BoPhan)sqlMapper.QueryForObject("GetBoPhan", null);
            
            var ok1 = sqlMapper.QueryForList("GetBoPhan", null);

            var lst1 = new List<Domain.BoPhan>();
            foreach (var r in ok1)
            {
                var rx = (Domain.BoPhan) r;
                lst1.Add(rx);
               
            }


            var ok2 = sqlMapper.QueryForList("GetVitri", null);

            var lst2 = new List<Domain.ViTri>();
            foreach (var r in ok2)
            {
                var rx = (Domain.ViTri)r;
                lst2.Add(rx);

            }

         var r1 = from s in lst1
                  select new {
                      ID=s.Id_Bophan ,
                      ParentID = Guid.Empty,
                      Ten = s.Ten_Bophan
            
        };


         var r2 = from s in lst2
                  select new
                  {
                      ID = s.Id_Vitri,
                      ParentID = s.Id_Bophan,
                      Ten = s.Ten_Vitri

                  };

         var r11 = r1.Union(r2);
          return Extension.Data.ToDataTable(r11);

           
        }
    }
}
